C++ Bitset 中的 operator[]函数

首页 / C++入门教程 / C++ Bitset 中的 operator[]函数

C ++位集函数用于访问值到位集的任何索引。

句法

boolean operator [] (int pos);
reference operator[] (int pos);

范围

pos strong>:参数 index strong>指定要分配值的位置 strong>。

返回值

该函数将值返回到索引处的位。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-bitset-operator[]-function.html

来源:LearnFk无涯教程网

例子1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b;
b[1]=1;
b[2]=b[1];
cout<< "b :" << b;
return 0;
}

输出 strong>:

b :0110

例子2

#include <iostream>
#include <bitset>
using namespace std;

int main()
{
bitset<4> b(string("1001"));
b[1]=1;
b[2]=b[1];
cout<< "b :" << b;
return 0;
}

输出 strong>:

b :1111



祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Android开发高手课 -〔张绍文〕

重学前端 -〔程劭非(winter)〕

Spring编程常见错误50例 -〔傅健〕

说透5G -〔杨四昌〕

郭东白的架构课 -〔郭东白〕

深入浅出分布式技术原理 -〔陈现麟〕

李智慧 · 高并发架构实战课 -〔李智慧〕

深入浅出可观测性 -〔翁一磊〕

手把手带你写一个MiniSpring -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)